package com.zhongke.DKYCboot.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhongke.DKYCboot.bean.BaseDriver;
import com.zhongke.DKYCboot.bean.ReceiveBaseDriver;
import com.zhongke.DKYCboot.mapper.BaseDriverMapper;
import com.zhongke.DKYCboot.service.BaseDriverService;
import com.zhongke.DKYCboot.util.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BaseDriverServiceImpl implements BaseDriverService {
    @Autowired
    BaseDriverMapper baseDriverMapper;

    //新增司机
    public Msg insertBaseDriver(BaseDriver baseDriver){
        //根据手机号查询是否有相同的数据
        BaseDriver baseDriver1=baseDriverMapper.getBaseDriverPhonenum(baseDriver.getDriverPhonenum());
        if (baseDriver1!=null){
            return Msg.fail("手机号已存在");
        }
        //根据身份证号查询是否有相同的数据
        BaseDriver baseDriver2=baseDriverMapper.getBasedriverIdnumber(baseDriver.getDriverIdnumber());
        if (baseDriver2!=null){
            return Msg.fail("身份证号已存在");
        }
        int i=baseDriverMapper.insertBaseDriver(baseDriver);
        if (i>0){
            return Msg.success("成功");
        }else{
            return Msg.fail("失败");
        }
    }

    //搜索司机
    @Override
    public Msg selectBaseDriverList(ReceiveBaseDriver receiveBaseDriver,int pageNum,int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<BaseDriver> baseDriverList=baseDriverMapper.selectBaseDriverList(receiveBaseDriver);
        PageInfo<BaseDriver> pageInfo = new PageInfo<BaseDriver>(baseDriverList);
        return Msg.success(pageInfo);
    }
    //更新司机信息
    public Msg updateBaseDriver(BaseDriver baseDriver){
        Integer i=baseDriverMapper.updateBaseDriver(baseDriver);
        if (i>0){
            return Msg.success("成功");
        }
        else {
            return Msg.fail("失败");
        }
    }
    //批量删除司机
    public Msg deleteBaseDriverMany(int[] ids,String updateBy){
        Integer i=baseDriverMapper.deleteBaseDriverMany(ids,updateBy);
        if (i>0){
            return Msg.success("成功");
        }
        else {
            return Msg.fail("失败");
        }
    }

}
